﻿USE WarehouseManagement
GO

ALTER PROCEDURE [Login]
(
@Username NVARCHAR(MAX),
@Password NVARCHAR(MAX)
)
AS
BEGIN
	
	DECLARE @EmployeeID Int = 0
	
	DECLARE @FullName nvarchar(MAX)

	SELECT 
			@EmployeeID = e.[EmployeeID],
			@FullName = e.[FullName]
	FROM 
			[Employee] e
	WHERE
			[UserName] = @Username
			
			AND [Password] = @Password

			AND [IsDelete] = 0
	--
	if (@EmployeeID != 0 AND @FullName IS NOT NULL)
	BEGIN
		SELECT @EmployeeID AS "EmployeeID", @FullName AS 'FullName'
		--
		SELECT 
			au.[Key]
		FROM 
			[Authorization] au
		INNER JOIN
			[AccountAuthorization] aa
		ON
			au.[AuthorizationID] = aa.[AuthorizationID] AND aa.[EmployeeID] = @EmployeeID
	END
END

/*
USE WarehouseManagement
GO
EXEC [Login] @Username = 'admin', @Password = 'admin@12345'
*/